package com.base.pojo;

import java.io.*;

/**
 * this is a class demo.
 *
 * @author pretty_boy
 * @date 2018/9/26 16:32
 */
public class IODemo {
    public static void main(String[] args) {
//        char c ;
//        try (BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in))) {
//            do {
//                 c = (char) bufferedReader.read();
//                System.out.println(c);
//            }while(c!='q');
//        }catch (IOException e) {
//            e.printStackTrace();
//        }
//
//        try (InputStream in = new FileInputStream("c:/Log_20180726.txt")) {
//            byte[] b = new byte[1024];
//            int len;
//            while ((len = in.read(b) )!= -1) {
//                for (byte b1 : b) {
//                    System.out.print((char) b1);
//                }
//            }
//
//        }catch(Exception e) {
//
//        }
        readerDemo();

    }

    //解决中文乱码问题
    public static void readerDemo() {
        try {
            InputStream in = new FileInputStream("c:/Log_20180726.txt");
            BufferedReader bf = new BufferedReader(new InputStreamReader(in,"GBK"));
            String s;
            StringBuilder sb = new StringBuilder();
            while ((s = bf.readLine()) != null) {
                sb.append(s);
                sb.append("\n");
            }
            System.out.println("sb = " + sb.toString());
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
